package com.rpp.utils;

import com.rpp.annotation.Autowired;
import com.rpp.annotation.Component;

import java.sql.SQLException;

/**
 * @Description
 * @Author rpp
 * @Date 2020/6/25 11:43 下午
 */
@Component
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    // 开启手动事务控制
    public void beginTransaction() throws SQLException {
        connectionUtils.getCurrentThreadConn().setAutoCommit(false);
        System.out.println("开启事务。。。。。。");
    }


    // 提交事务
    public void commit() throws SQLException {
        connectionUtils.getCurrentThreadConn().commit();
        System.out.println("提交事务。。。。。。");
    }


    // 回滚事务
    public void rollback() throws SQLException {
        connectionUtils.getCurrentThreadConn().rollback();
        System.out.println("回滚事务。。。。。。");
    }
}
